<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/faculty/editArchiveStatus.css"/>

<div class="faculty">
    <div class="editArchiveStatus">
        <p>Are you sure you wish to <?php if($status == 1) echo 'Archive'; else echo 'Un-archive';?> this profile?</p>
        <p class="error"><?php echo $lastname.", ".$firstname." ".$middlename?></p>
    </div>
    <?php echo form_open('faculty/changeArchiveStatus/'.$id, array('class' => 'form-search', 'id' => "change_status")) ?>
        <input type="hidden" name="status" value="<?php echo $status;?>">
    <? echo form_close()?>
</div>

<div class="growUI"></div>

<script>
    $('#change_status').on('submit', function(e){
        e.preventDefault();

        $.ajax({
            //this is the php file that processes the data and send mail
            url: "<?php echo base_url();?>faculty/changeArchiveStatus/<?php echo $id?>",
            //GET method is used
            type: "POST",
            data: $('#change_status').serialize(),
            //success
            dataType: "json",
            success: function (data, $textStatus, $asdf) {
                console.log(data);

                if(data.status == 'Success')
                {
                    searchResults = $('.search-result .btnArchive');

                    for(int = 0; int < searchResults.size(); int++)
                    {
                        btn = searchResults[int];
                        id = $(btn).parent().parent().parent().attr('id');

                        if(id == <?php echo $id?>)
                        {
                            newstatusstring = '';
                            if(data.newstatus == 1)
                                newstatusstring = 'Archive Profile';
                            else
                                newstatusstring = 'Un-archive Profile';
                            $(btn).html(newstatusstring);
                            break;
                        }
                    }//*/

                    $.growlUI(data.status, data.message);
                }
                $( "#archive-member" ).dialog( "close" );
            },
            error: function (data, textStatus, errorThrown) {
                console.log(data);
                console.log('error');
            }
        });

    });
</script>